﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ESOL.Common.Entity;
using ESOL.Common;
using ESOL.Business.Fa;

namespace ESOL.WinUI.Fa
{
    public partial class frmManageMyAsset : BaseForm.frmBaseMdiBusinessForm
    {
        #region Variable
        private FaAssetsEntity mSelectedAsset;
        #endregion

        #region Construction
        public frmManageMyAsset()
        {
            InitializeComponent();
        }
        #endregion
        #region Function
        private void BindComboBox()
        {
            UICommon.UICommonFunctions.BindGridComboboxByCommonItem(repositoryItemGridLookUpEdit1, "FAS", true);
        }
        private string GetCondition()
        {
            string condition = " AND P.PERSON_ID = '" + CommonParameter.CurrentUser.PersonId + "' ";
            return condition;
        }
        private void BindDataGrid()
        {
            string condition = GetCondition();
            string rowCount = txtRowCount.Text;
            string orderBy = "AT2.ASSET_TYPE_NAME, AT1.ASSET_TYPE_NAME, A.ASSET_CODE";
            DataTable dt = FaAssetsBs.GetUsedInfoByCondition(condition, orderBy, rowCount);
            gvMain.DataSource = dt;
        }
        #endregion

        private void frmManageMyAsset_Load(object sender, EventArgs e)
        {
            txtPerson.Text = CommonParameter.CurrentUser.PersonEntity.NameCn + " (" + CommonParameter.CurrentUser.PersonEntity.PersonCode + ")";
            BindComboBox();
            BindDataGrid();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            DataRow dr = gridView1.GetDataRow(e.RowHandle);
            mSelectedAsset = new FaAssetsEntity(dr);
        }
        protected override void Click_Query()
        {
            BindDataGrid();
        }
        protected override void Click_View()
        {
            if (mSelectedAsset == null)
            {
                MessageBox.Show("请选择一个固定资产！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            frmMaintainAsset frm = new frmMaintainAsset();
            frm.ThisActionType = ActionType.View;
            frm.mSelectedAsset = mSelectedAsset;
            frm.ShowDialog();
        }


    }
}